package com.gupaoedu.vip.pattern.singleton.register;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * Created by Administrator on 2018/3/18.
 */
public class BeanFactory {

    private static Map<String,Object> map = new ConcurrentHashMap<String,Object>();

    public static Object getBean(String beanName){
        if(map.containsKey(beanName)){
           return map.get(beanName);
        }

        Object obj = null;
        try {
            obj = Class.forName(beanName).newInstance();
            map.put(beanName,obj);
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        return obj;
    }
}
